package com.local.article.pojo;

import org.springframework.data.annotation.Id;
import org.springframework.data.mongodb.core.index.CompoundIndex;
import org.springframework.data.mongodb.core.index.IndexDirection;
import org.springframework.data.mongodb.core.index.Indexed;
import org.springframework.data.mongodb.core.mapping.Document;
import org.springframework.data.mongodb.core.mapping.Field;

import java.io.Serializable;
import java.time.LocalDateTime;
import java.util.Date;

@Document(collection = "comment") //collection可以省略，如果省略则使用类名小写对应的集合
@CompoundIndex(def = "{userid: 1, nickname: -1}") //添加复合索引
public class Comment implements Serializable {

    @Id //主键标识，该属性的值会自动对应mongodb集合的“_id”字段。如果属性名就叫id，则注解可以省略
    private String id;
    private String articleid;
    @Field("content") //该属性对应mongodb中的content字段，如果名字一致，则无需注解
    private String content;
    @Indexed(name = "userid_1", background = true, direction = IndexDirection.ASCENDING) //添加一个单字段索引
    private String userid;
    private String nickname;
    private LocalDateTime createdatetime;
    private Integer likenum;
    private String parentid;
    private String state;

    public Comment(){}

    public Comment(String id, String articleid, String content, String userid, String nickname, LocalDateTime createdatetime, Integer likenum, String parentid, String state) {
        this.id = id;
        this.articleid = articleid;
        this.content = content;
        this.userid = userid;
        this.nickname = nickname;
        this.createdatetime = createdatetime;
        this.likenum = likenum;
        this.parentid = parentid;
        this.state = state;
    }

    public String getId() {
        return id;
    }

    public void setId(String id) {
        this.id = id;
    }

    public String getArticleid() {
        return articleid;
    }

    public void setArticleid(String articleid) {
        this.articleid = articleid;
    }

    public String getContent() {
        return content;
    }

    public void setContent(String content) {
        this.content = content;
    }

    public String getUserid() {
        return userid;
    }

    public void setUserid(String userid) {
        this.userid = userid;
    }

    public String getNickname() {
        return nickname;
    }

    public void setNickname(String nickname) {
        this.nickname = nickname;
    }

    public LocalDateTime getCreatedatetime() {
        return createdatetime;
    }

    public void setCreatedatetime(LocalDateTime createdatetime) {
        this.createdatetime = createdatetime;
    }

    public Integer getLikenum() {
        return likenum;
    }

    public void setLikenum(Integer likenum) {
        this.likenum = likenum;
    }

    public String getParentid() {
        return parentid;
    }

    public void setParentid(String parentid) {
        this.parentid = parentid;
    }

    public String getState() {
        return state;
    }

    public void setState(String state) {
        this.state = state;
    }

    @Override
    public String toString() {
        return "Comment{" +
                "id='" + id + '\'' +
                ", articleid='" + articleid + '\'' +
                ", content='" + content + '\'' +
                ", userid='" + userid + '\'' +
                ", nickname='" + nickname + '\'' +
                ", createdatetime=" + createdatetime +
                ", likenum=" + likenum +
                ", parentid='" + parentid + '\'' +
                ", state='" + state + '\'' +
                '}';
    }
}
